<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        td {
            border: 1px solid black;
        }
    </style>
</head>
<!--该案例有删除提交功能，表单部分是作为一个组件
    bug1；见注释
    bug2:使用form作为表单的名称是错的
    bug3:component拼写错误，检查里没有提示
    bug4:定义的变量form1放在了脚本的最后面是错的

-->

<body>

    <div id="a">
        <form1 @tijiao2='tijiao'></form1>

        <table id='a'>
            <thead>
                <tr>
                    <td>id</td>
                    <td>name</td>
                    <td>ctime</td>
                    <td>operation</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for='(it,index) in shuju' :key='it.id'>
                    <td>{{it.id}}</td>
                    <td>{{it.name}}</td>
                    <td>{{it.ctime}}</td>
                    <td @click='shanchu(index)'>删除</td>
                </tr>
            </tbody>
            <tfoot></tfoot>
        </table>

    </div>
    <template id="form1">
       
        <div>
            id:<input type="text" v-model='id'>
            name :<input type="text" v-model='name'>
            <input type="button" value="提交"@click='tijiao1(id,name)'>
        </div>
    </template>
    <script>
        var form1 = {
            template: '#form1',
            data: function() {
                return {
                    id: 'idwu',
                    name: 'namewu'
                }
            },
            methods: {
                tijiao1: function(id, name) {

                    this.$emit('tijiao2', id, name);
                }

            }
        }
        new Vue({
                el: '#a',
                data: {
                    id: '',
                    name: '',
                    shuju: [{
                        name: 'a',
                        id: 1,
                        ctime: 12

                    }, {
                        name: 'b',
                        id: 2,
                        ctime: 12
                    }, {
                        name: 'c',
                        id: 3,
                        ctime: 12
                    }, {
                        name: 'd',
                        id: 4,
                        ctime: 12
                    }, {
                        name: 'e',
                        id: 5,
                        ctime: 12
                    }],
                },
                methods: {
                    tijiao: function(id, name) {
                        this.shuju.push({
                            name: name,
                            id: id
                        });
                    },
                    shanchu: function(index) {

                        this.shuju.splice(index, 1);
                    }
                },
                components: {
                    form1: form1
                        // 这里之前写成“form1”: form1是错的
                }
            })
            // var form1 = {
            //     template: '#form1'
            // }变量放下面是错的
    </script>
</body>

</html>